package hrms.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import hrms.entity.Company;
import hrms.service.CompanyService;
import hrms.util.LogUtil;
import hrms.util.Result;

@Controller
public class IndexController {

	@Resource(name = "companyService")
	private CompanyService service;

	@ExceptionHandler
	public String exHandle(Exception ex, HttpServletRequest req) {
		LogUtil.saveEx(ex);
		return "error";
	}

	@ResponseBody
	@RequestMapping("/title.sls")
	public Result<List<Company>> executeTitle(HttpServletRequest req) {
		String index = req.getParameter("index");
		Result<List<Company>> result = service.findAll(index);
		return result;
	}

	@ResponseBody
	@RequestMapping("/detail.sls")
	public Result<Map<String, String>> executeDetail(HttpServletRequest req) {
		String id = req.getParameter("id");
		Result<Map<String, String>> result = service.findDetail(id);
		return result;
	}

	// 转到系统管理
	@RequestMapping("/toSystem.sls")
	public String toSystem() {
		return "system/system";
	}

	// 转到部门管理
	@RequestMapping("/toDept.sls")
	public String toDept() {
		return "dept/dept";
	}

	// 转到员工管理
	@RequestMapping("/toEmp.sls")
	public String toEmp() {
		return "emp/emp";
	}

	// 转到招聘管理
	@RequestMapping("/toWanted.sls")
	public String toWanted() {
		return "wanted/wanted";
	}

	// 转到培训管理
	@RequestMapping("/toTrain.sls")
	public String toTrain() {
		return "train/train";
	}

	// 转到薪资管理
	@RequestMapping("/toSalary.sls")
	public String toSalary() {
		return "salary/salary";
	}

	// 转到奖惩管理
	@RequestMapping("/toReward.sls")
	public String toReward() {
		return "reward/reward";
	}

	// 下载
	@RequestMapping("/toExcel.sls")
	public String toExcel() {
		return "excel";
	}

	// 转到奖惩管理
	@RequestMapping("/toDemo.sls")
	public String toDemo() {
		return "demo/demoIndex";
	}
}
